<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    /* 
      思路：https://leetcode-cn.com/problems/coin-change/solution/322-ling-qian-dui-huan-you-hua-dong-tai-gui-hua-c-/
      https://leetcode-cn.com/problems/coin-change/solution/js-xiang-jie-dong-tai-gui-hua-de-si-xiang-yi-bu-da/
    */
    var coinChange = function(coins, amount) {
      let dp = new Array(amount+1).fill(Infinity);
      dp[0] = 0;
      for (let coin of coins) {
        for (let i = coin; i <= amount; i++) {
          dp[i] = Math.min(dp[i], dp[i-coin] + 1);
        }
      }

      return dp[amount] === Infinity ? -1 : dp[amount];
    };
  </script>
</body>
</html>